home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfwddx.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.4 KB  |  68 lines

  1. <!--- This example shows the use of CFWDDX --->
  2. <HTML>
  3. <HEAD>
  4. <TITLE>CFWDDX Example</TITLE>
  5. </HEAD>
  6.  
  7. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  8. <BODY  bgcolor="#FFFFD5">
  9.  
  10. <H3>CFWDDX Example</H3>
  11.  
  12. <P>The CFWDDX tag can be used to serialize and de-serialize CFML data structures to the XML-based WDDX
  13. format. It can also be used to generate JavaScript statements instantiating JavaScript objects equivalent to the
  14. contents of a WDDX packet or some CFML data structures.
  15.  
  16. <P>The following example demonstrates the serialization/deserialization of CFML data structures. First a complex
  17. CFML data structures is built. It consists of a one-dimensional array whose elements are of different types:
  18. numbers, strings, booleans, date-time values, and even a query. 
  19.  
  20. The data structure is then serialized to create a WDDX packet in the variable wddxPacket. The packet is
  21. outputted so that its contents can be inspected. This step demonstrates the serialization of CFML data structures
  22. to the WDDX format.
  23.  
  24. To demonstrate the deserialization of CFML data structures, the WDDX packet is deserialized and the resulting
  25. CFML data structure stored in the variable wddxResult. To verify the success of the deserialization, some of the
  26. columns of the deserialized query are outputted.
  27.  
  28. <!--- Create a simple query  --->
  29. <CFQUERY NAME='q' DATASOURCE="cfsnippets">
  30.         SELECT Message_Id, Thread_id, Username, Posted FROM Messages
  31. </CFQUERY>
  32.  
  33. <!--- Create a simple array --->
  34. <CFSET a = ArrayNew(1)>
  35. <CFLOOP INDEX=i from=1 to=5>
  36.         <CFSET a[i] = 'This is array element ###i#'>
  37. </CFLOOP>
  38.  
  39. <!--- Show polymorphic data storage --->
  40. <CFSET a[6] = true>
  41. <CFSET a[7] = -12.456>
  42. <CFSET a[8] = CreateDateTime(1996, 8, 1, 2, 3, 4)>
  43. <CFSET a[9] = q>
  44.  
  45. <!--- Serialize data to WDDX format --->
  46. Serializing CFML data...<p>
  47. <CFWDDX ACTION='cfml2wddx' INPUT=#a# OUTPUT='wddxText'>
  48.  
  49. <!--- Display WDDX XML packet --->
  50. Resulting WDDX packet is:
  51. <XMP><CFOUTPUT>#wddxText#</CFOUTPUT></XMP>
  52.  
  53. <!--- Deserialize to a variable named wddxResult --->
  54. Deserializing WDDX packet...<p>
  55. <CFWDDX ACTION='wddx2cfml' INPUT=#wddxText# OUTPUT='wddxResult'>
  56.  
  57. <!--- Extract the query at array position 9 and output some data --->
  58. Message_ID, Thread_ID, and Username columns from the deserialized query recordset:<p>
  59.  
  60. <CFSET qnew = wddxResult[9]>
  61.  
  62. <CFOUTPUT QUERY=qnew>
  63.      #Message_ID# #Thread_ID# #Username#<BR>
  64. </CFOUTPUT>
  65.  
  66. </BODY>
  67. </HTML>       
  68.